home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Games / NetHack 3.1.3 / source / include / winX.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-01  |  11.7 KB  |  339 lines  |  [TEXT/R*ch]

  1. /*    SCCS Id: @(#)winX.h    3.1    93/04/26          */
  2. /* Copyright (c) Dean Luick, 1992                  */
  3. /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5. /*
  6.  * Definitions for the X11 window-port.  See doc/window.doc for details on
  7.  * the window interface.
  8.  */
  9. #ifndef WINX_H
  10. #define WINX_H
  11.  
  12. #ifndef E
  13. #define E extern
  14. #endif
  15.  
  16. #if defined(BOS) || defined(NHSTDC)
  17. #define DIMENSION_P int
  18. #else
  19. # ifdef WIDENED_PROTOTYPES
  20. #define DIMENSION_P unsigned int
  21. # else
  22. #define DIMENSION_P Dimension
  23. # endif
  24. #endif
  25.  
  26. /*
  27.  * Generic text buffer.
  28.  */
  29. #define START_SIZE 512    /* starting text buffer size */
  30. struct text_buffer {
  31.     char *text;
  32.     int  text_size;
  33.     int  text_last;
  34.     int  num_lines;
  35. };
  36.  
  37.  
  38. /*
  39.  * Information specific to a map window.
  40.  */
  41. struct map_info_t {
  42.     unsigned char   text[ROWNO][COLNO],    /* Actual displayed screen. */
  43.             t_start[ROWNO],    /* Staring column for new info. */
  44.             t_stop[ROWNO];    /* Ending column for new info. */
  45.     int            char_width,        /* Saved font information so we can  */
  46.             char_height,    /*   calculate the correct placement */
  47.             char_ascent,    /*   of changes.             */
  48.             char_lbearing;
  49.     Dimension        viewport_width,    /* Saved viewport size, so we can */
  50.             viewport_height;    /*   clip to cursor on a resize.  */
  51. #ifdef TEXTCOLOR
  52.     unsigned char   colors[ROWNO][COLNO];    /* Color of each character. */
  53.     GC            color_gcs[MAXCOLORS],    /* GC for each color */
  54.             inv_color_gcs[MAXCOLORS];    /* GC for each inverse color */
  55. #define copy_gc     color_gcs[NO_COLOR]
  56. #define inv_copy_gc inv_color_gcs[NO_COLOR]
  57. #else
  58.     GC            copy_gc,            /* Drawing GC */
  59.             inv_copy_gc;        /* Inverse drawing GC */
  60. #endif
  61. };
  62.  
  63. /*
  64.  * Information specific to a message window.
  65.  */
  66. struct line_element {
  67.     struct line_element *next;
  68.     char *line;            /* char buffer */
  69.     int  buf_length;        /* length of buffer */
  70.     int  str_length;        /* length of string in buffer */
  71. };
  72.  
  73. struct mesg_info_t {
  74.     XFontStruct *fs;        /* Font for the window. */
  75.     int        num_lines;    /* line count */
  76.     struct line_element *head;    /* head of circular line queue */
  77.     struct line_element *line_here;/* current drawn line position */
  78.     struct line_element *last_pause;/* point to the line after the prev */
  79.                 /*     bottom of screen            */
  80.     struct line_element *last_pause_head;/* pointer to head of previous */
  81.                 /* turn                    */
  82.     GC        gc;        /* GC for text drawing */
  83.     int         char_width,     /* Saved font information so we can  */
  84.         char_height,    /*   calculate the correct placement */
  85.         char_ascent,    /*   of changes.                     */
  86.         char_lbearing;
  87.     Dimension    viewport_width,    /* Saved viewport size, so we can adjust */
  88.         viewport_height;/*   the slider on a resize.         */
  89.     Boolean    dirty;        /* Lines have been added to the window. */
  90. };
  91.  
  92. /*
  93.  * Information specific to a "text" status window.
  94.  */
  95. struct status_info_t {
  96.     struct text_buffer text;    /* Just a text buffer. */
  97. };
  98.  
  99. /*
  100.  * Information specific to a menu window.  First a structure for each
  101.  * menu entry, then the structure for each menu window.
  102.  */
  103. struct menu_item {
  104.     struct menu_item *next;
  105.     char selector;        /* Char used to select this entry. */
  106.     int  attr;            /* Attribute for the line. */
  107.     char *str;            /* The text of the item. */
  108. };
  109.  
  110. struct menu_info_t {
  111.     struct menu_item *base;    /* Starting pointer for item list. */
  112.     struct menu_item *last;    /* End pointer for item list. */
  113.     const char    *query;
  114.     const char    *other_valid;
  115.     char    other_response;
  116.     int     count;
  117.     String  *list_pointer;
  118.     boolean valid_widgets;
  119.     boolean is_menu;        /* Has been conformed to being a menu window. */
  120. };
  121.  
  122. /*
  123.  * Information specific to a text window.
  124.  */
  125. struct text_info_t {
  126.     struct text_buffer text;
  127.     XFontStruct *fs;        /* Font for the text window. */
  128.     int        max_width;    /* Width of widest line so far. */
  129.     int        extra_width,    /* Sum of left and right border widths. */
  130.         extra_height;    /* Sum of top and bottom border widths. */
  131.     boolean    blocked;    /*  */
  132.     boolean    destroy_on_ack;    /* Destroy this window when acknowleged. */
  133. };
  134.  
  135.  
  136. /*
  137.  * Basic window structure.
  138.  */
  139. struct xwindow {
  140.     int          type;        /* type of nethack window */
  141.     Widget    popup;        /* direct parent of widget w or viewport */
  142.     Widget    w;        /* the widget that does things */
  143.     Dimension pixel_width;    /* window size, in pixels */
  144.     Dimension pixel_height;
  145.     int          prevx, cursx;    /* Cursor position, only used by    */
  146.     int       prevy, cursy;    /*   map and "plain" status windows.*/
  147.  
  148.     union {
  149.     struct map_info_t    *Map_info;        /* map window info */
  150.     struct mesg_info_t   *Mesg_info;    /* message window info */
  151.     struct status_info_t *Status_info;  /* status window info */
  152.     struct menu_info_t   *Menu_info;    /* menu window info */
  153.     struct text_info_t   *Text_info;    /* menu window info */
  154.     } Win_info;
  155. };
  156.  
  157. /* Defines to use for the window information union. */
  158. #define map_information    Win_info.Map_info
  159. #define mesg_information   Win_info.Mesg_info
  160. #define status_information Win_info.Status_info
  161. #define menu_information   Win_info.Menu_info
  162. #define text_information   Win_info.Text_info
  163.  
  164.  
  165. #define MAX_WINDOWS 20        /* max number of open windows */
  166.  
  167. #define NHW_NONE 0        /* Unallocated window type.  Must be     */
  168.                 /* different from any other NHW_* type. */
  169.  
  170. #define NO_CLICK 0        /* No click occured on the map window. Must */
  171.                 /* be different than CLICK_1 and CLICK_2.   */
  172.  
  173. #define DEFAULT_MESSAGE_WIDTH 60/* width in chars of the message window */
  174.  
  175. #define DISPLAY_FILE_SIZE 35    /* Max number of lines in the default    */
  176.                 /* file display window.            */
  177.  
  178. #define MAX_KEY_STRING 64    /* String size for converting a keypress */
  179.                 /* event into a character(s)         */
  180.  
  181. #define DEFAULT_LINES_DISPLAYED 12 /* # of lines displayed message window */
  182. #define MAX_HISTORY 60        /* max history saved on message window */
  183.  
  184.  
  185. /* Window variables (winX.c). */
  186. E struct xwindow window_list[MAX_WINDOWS];
  187. E XtAppContext   app_context;        /* context of application */
  188. E Widget     toplevel;        /* toplevel widget */
  189. E Atom         wm_delete_window;    /* delete window protocol */
  190. E boolean     exit_x_event;        /* exit condition for event loop */
  191. #define EXIT_ON_KEY_PRESS        0    /* valid values for exit_x_event */
  192. #define EXIT_ON_KEY_OR_BUTTON_PRESS 1
  193. #define EXIT_ON_EXIT            2
  194. #define EXIT_ON_SENT_EVENT        3
  195. E int click_x, click_y, click_button;
  196.  
  197. typedef struct {
  198.     Boolean slow;
  199.     Boolean autofocus;
  200.     Boolean message_line;
  201.     String  icon;    /* name of desired icon */
  202. } AppResources;
  203.  
  204. E AppResources appResources;
  205. E void (*input_func)();
  206.  
  207. extern struct window_procs X11_procs;
  208.  
  209. /* Check for an invalid window id. */
  210. #define check_winid(window)                    \
  211.     if ((window) < 0 || (window) >= MAX_WINDOWS) {        \
  212.         panic("illegal windid [%d] in %s at line %d",    \
  213.         window, __FILE__, __LINE__);            \
  214.     }
  215.  
  216.  
  217. /* ### dialogs.c ### */
  218. E Widget FDECL(CreateDialog, (Widget, String, XtCallbackProc, XtCallbackProc));
  219. E void FDECL(SetDialogPrompt,(Widget, String));
  220. E String FDECL(GetDialogResponse,(Widget));
  221. E void FDECL(SetDialogResponse,(Widget, String));
  222. E void FDECL(positionpopup,(Widget,BOOLEAN_P));
  223.  
  224. /* ### winX.c ### */
  225. E struct xwindow *FDECL(find_widget,(Widget));
  226. E char FDECL(key_event_to_char,(XKeyEvent*));
  227. E void FDECL(msgkey, (Widget, XtPointer, XEvent*));
  228. E void FDECL(nh_XtPopup, (Widget, int, Widget));
  229. E void FDECL(nh_XtPopdown, (Widget));
  230. E void NDECL(win_X11_init);
  231.  
  232. /* ### winmesg.c ### */
  233. E void FDECL(set_message_slider, (struct xwindow*));
  234. E void FDECL(create_message_window,(struct xwindow*, BOOLEAN_P, Widget));
  235. E void FDECL(destroy_message_window,(struct xwindow*));
  236. E void FDECL(display_message_window, (struct xwindow*));
  237. E void FDECL(append_message,(struct xwindow*, const char*));
  238. E void FDECL(set_last_pause, (struct xwindow*));
  239.  
  240. /* ### winmap.c ### */
  241. E void FDECL(check_cursor_visibility,(struct xwindow*));
  242. E void FDECL(display_map_window,(struct xwindow*));
  243. E void FDECL(clear_map_window,(struct xwindow*));
  244. E void FDECL(map_input, (Widget, XEvent*, String*, Cardinal*));
  245. E void FDECL(set_map_size,(struct xwindow*, DIMENSION_P, DIMENSION_P));
  246. E void FDECL(create_map_window,(struct xwindow*, BOOLEAN_P, Widget));
  247. E void FDECL(destroy_map_window,(struct xwindow*));
  248. E int  FDECL(x_event,(int));
  249.  
  250. /* ### winmenu.c ### */
  251. E void FDECL(menu_delete, (Widget, XEvent*, String*, Cardinal*));
  252. E void FDECL(menu_key,(Widget, XEvent*, String*, Cardinal*));
  253. E void FDECL(create_menu_window,(struct xwindow*));
  254. E void FDECL(destroy_menu_window,(struct xwindow*));
  255.  
  256. /* ### winmisc.c ### */
  257. E void FDECL(ps_key,(Widget, XEvent*, String*, Cardinal*)); /* player selection action */
  258. E void FDECL(ec_delete, (Widget, XEvent*, String*, Cardinal*));
  259. E void FDECL(ec_key,(Widget, XEvent*, String*, Cardinal*)); /* extended command action */
  260. E void NDECL(init_extended_commands_popup);
  261.  
  262. /* ### winstatus.c ### */
  263. E void FDECL(create_status_window,(struct xwindow*, BOOLEAN_P, Widget));
  264. E void FDECL(destroy_status_window,(struct xwindow*));
  265. E void FDECL(adjust_status,(struct xwindow*, const char*));
  266. E void NDECL(null_out_status);
  267. E void NDECL(check_turn_events);
  268.  
  269. /* ### wintext.c ### */
  270. E void FDECL(delete_text, (Widget, XEvent*, String*, Cardinal*));
  271. E void FDECL(dismiss_text,(Widget, XEvent*, String*, Cardinal*));
  272. E void FDECL(key_dismiss_text,(Widget, XEvent*, String*, Cardinal*));
  273. E void FDECL(add_to_text_window,(struct xwindow*, int, const char*));
  274. E void FDECL(display_text_window,(struct xwindow*, BOOLEAN_P));
  275. E void FDECL(create_text_window,(struct xwindow*));
  276. E void FDECL(destroy_text_window,(struct xwindow*));
  277. E void FDECL(append_text_buffer,(struct text_buffer*, const char*, BOOLEAN_P));    /* text buffer routines */
  278. E void FDECL(init_text_buffer,(struct text_buffer*));
  279. E void FDECL(clear_text_buffer,(struct text_buffer*));
  280. E void FDECL(free_text_buffer,(struct text_buffer*));
  281.  
  282. /* ### winval.c ### */
  283. E Widget FDECL(create_value,(Widget, const char*));
  284. E void   FDECL(set_name,(Widget, char*));
  285. E void   FDECL(set_name_width,(Widget, int));
  286. E int    FDECL(get_name_width,(Widget));
  287. E void   FDECL(set_value,(Widget, const char*));
  288. E void   FDECL(set_value_width,(Widget, int));
  289. E int    FDECL(get_value_width,(Widget));
  290. E void   FDECL(hilight_value,(Widget));
  291.  
  292. /* external declarations */
  293. E void NDECL(X11_init_nhwindows);
  294. E void NDECL(X11_player_selection);
  295. E void NDECL(X11_askname);
  296. E void NDECL(X11_get_nh_event) ;
  297. E void FDECL(X11_exit_nhwindows, (const char *));
  298. E void FDECL(X11_suspend_nhwindows, (const char *));
  299. E void NDECL(X11_resume_nhwindows);
  300. E winid FDECL(X11_create_nhwindow, (int));
  301. E void FDECL(X11_clear_nhwindow, (winid));
  302. E void FDECL(X11_display_nhwindow, (winid, BOOLEAN_P));
  303. E void FDECL(X11_destroy_nhwindow, (winid));
  304. E void FDECL(X11_curs, (winid,int,int));
  305. E void FDECL(X11_putstr, (winid, int, const char *));
  306. E void FDECL(X11_display_file, (const char *, BOOLEAN_P));
  307. E void FDECL(X11_start_menu, (winid));
  308. E void FDECL(X11_add_menu, (winid, CHAR_P, int, const char *));
  309. E void FDECL(X11_end_menu, (winid, CHAR_P, const char *, const char *));
  310. E char FDECL(X11_select_menu, (winid));
  311. E void NDECL(X11_update_inventory);
  312. E void NDECL(X11_mark_synch);
  313. E void NDECL(X11_wait_synch);
  314. #ifdef CLIPPING
  315. E void FDECL(X11_cliparound, (int, int));
  316. #endif
  317. E void FDECL(X11_print_glyph, (winid,XCHAR_P,XCHAR_P,int));
  318. E void FDECL(X11_raw_print, (const char *));
  319. E void FDECL(X11_raw_print_bold, (const char *));
  320. E int NDECL(X11_nhgetch);
  321. E int FDECL(X11_nh_poskey, (int *, int *, int *));
  322. E void NDECL(X11_nhbell);
  323. E int NDECL(X11_doprev_message);
  324. E char FDECL(X11_yn_function, (const char *, const char *, CHAR_P));
  325. E void FDECL(X11_getlin, (const char *,char *));
  326. #ifdef COM_COMPL
  327. E void FDECL(X11_get_ext_cmd, (char *));
  328. #endif /* COM_COMPL */
  329. E void FDECL(X11_number_pad, (int));
  330. E void NDECL(X11_delay_output);
  331.  
  332. /* other defs that really should go away (they're tty specific) */
  333. E void NDECL(X11_start_screen);
  334. E void NDECL(X11_end_screen);
  335.  
  336. E void FDECL(genl_outrip, (winid,int));
  337.  
  338. #endif /* WINX_H */
  339.